<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>{:session('cp.cpsysname')}--商户管理平台</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
    <meta name="description" content="{:config('webconfig.description');}">
    <meta name="keywords" content="{:config('webconfig.keywords');}">
    <meta name="author" content="runoob">
    <link rel="stylesheet" href="__STATIC_URL__/static/css/bootstrap.css">
    <link rel="stylesheet" type="text/css" href="__STATIC_URL__/static/css/index.css"/>
    <link rel="stylesheet" href="__STATIC_URL__/static/css/bootstrapSwitch.css">

    <link rel="stylesheet" href="__STATIC_URL__/static/css/creatcard.css"/>
    <link rel="stylesheet" href="__STATIC_URL__/static/css/coupon.css"/>
    <link rel="stylesheet" type="text/css" href="__STATIC_URL__/static/css/core.css?v=5"/>

    <link rel="stylesheet" type="text/css" href="__STATIC_URL__/static/css/setyxhd.css?v=5"/>
    <link rel="stylesheet" type="text/css" href="__STATIC_URL__/static/fonts/css/font-awesome.css?v=3"/>
    <script src="__STATIC_URL__/static/js/jquery-2.1.4.min.js"></script>
    <script src="__STATIC_URL__/static/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script src="__STATIC_URL__/static/js/bootstrapSwitch.js"></script>
    <script src="__STATIC_URL__/static/layer/3.0.3/layer.js"></script>

    <style>
        .filePicker {
            margin-top: -5px;
            width: 150px;
            height: 44px;
            background: #00A2D4;
            color: #fff;
            text-align: center;
            line-height: 44px;
            border-radius: 4px;
            cursor: pointer;
        }

        .file {
            position: absolute;
            left: 14px;
            top: -5px;
            width: 150px;
            height: 44px;
            line-height: 44px;
            opacity: 0;
            cursor: pointer;
        }

        .img-file {
            width: 100px;
            height: 100px;
            display: block;
            margin-left: 26px;
            margin-top: 10px;
            display: none;
        }

        .form-control {
            width: 50%;
        }

        .ng-scope input {
            width: 82px;
            height: 34px;
            position: absolute;
            left: 0;
            top: 0;
            opacity: 0;
            cursor: pointer;
        }

        .ant-upload-list-item-info {
            width: 288px;
            height: 150px;
            padding: 0;
        }

        .ant-upload.ant-upload-select-picture-card {

            width: 288px;
            height: 150px;
            padding: 0;

        }
    </style>
</head>
<body >
{include file='public/header'/}
<!------------------导航-------------------------->
<section id="content">
    {include file='public/left'/}
    <!--------------------------主要内容区域------------------------------------->
    <div class="content">
        <div class="panel">
            <div class="panel-body">
                <div class="page-heading mgr15 mgl15">
                    <ul class="breadcrumb">
                        <li>当前位置是:</li>
                        <li>
                            <a href="{:url('cardus/cardinfo',['card_id'=>$card['card_id']])}">会员卡</a>
                        </li>
                        <li>
                            <a href="javascript:history.back();">会员等级</a>
                        </li>
                        <li class="active" style="color: #02b87f;">修改会员等级</li>
                    </ul>
                </div>
                <div class="panel panel-default c_content">
                    <form class="form-horizontal adminex-form" action='' method="post" id="creatcards">
                        <div class="headings gengduoxian">
                            <i class="infoLine"></i>会员等级
                        </div>
                        <div class="panel-body">
                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">等级名称：</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control" name='live_title' value="{$info.live_title}"
                                           placeholder="">
                                    <div class="error">请输入等级名称，例如白银会员、黄金会员等</div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">等级：</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control" name='live' value="{$info.live}"
                                           placeholder="">
                                    <div class="error">请输入等级数字，例如：1</div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">所需成长值：</label>
                                <div class="col-sm-10">
                                    <input type="text" value="{$info.growup}" class="form-control" name='growup'
                                           oninput="value = value.replace(/[^\d.]/g, '')" placeholder="">
                                    <div class="error">当用户成长值达到该数值时则升级为当前等级</div>
                                </div>
                            </div>
                            <!--<div class="form-group">-->
                            <!--<label class="col-sm-2 col-sm-2 control-label">积分系数(%)：</label>-->
                            <!--<div class="col-sm-10">-->
                            <!--<input type="text" value="{$info.bonus_dis}" class="form-control"-->
                            <!--oninput="value = value.replace(/[^\d.]/g, '')" name='bonus_dis' placeholder="">-->
                            <!--<div class="error">100%表示用户消费1元赠送1积分,10%则表示用户消费10元赠送1积分</div>-->
                            <!--</div>-->
                            <!--</div>-->
                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">折扣系数(%)：</label>
                                <div class="col-sm-10">
                                    <input type="text" value="{$info.discount}" class="form-control"
                                           oninput="value = value.replace(/[^\d.]/g, '')" name='discount'
                                           placeholder="">
                                    <div class="error">如打8折,则填写80</div>
                                </div>
                            </div>
                            <div class="form-horizontal" data-layout="horizontal">
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">活动奖品</label>
                                    <div class="col-sm-10">

                                        <div style=" margin-top:3px;">
                                            <div class="checkbox checkbox-info checkbox-inline prize">
                                                <input type="hidden" id="isbonus" value="{$info.is_bonus}"
                                                       name="is_bonus">
                                                <input type="checkbox" id="bonus" class="gift-input">
                                                <label for="bonus"> 奖励积分 </label>
                                                <span class="container" style="display:none;">
    							                                <div class="col-md-6 pannel charge-rule-box"
                                                                     style="float:none;margin-top:10px;margin-left: -22px;width: 400px;">
                                                                    <div style="margin-top:10px;" class="gift-record">
    											                          <input type="number"
                                                                                 class="form-control prize-gift" min="1"
                                                                                 onkeyup="this.value=this.value.replace(/\D/g,&#39;&#39;)"
                                                                                 style="width: 80px;margin-left: 3px;display: inline-block;"
                                                                                 placeholder="请填写" name="reward_bonus"
                                                                                 value="{$info.reward_bonus}">
                                                                          <span style=" margin-left: 75px;line-height:38px;">积分</span>
                                                                          <a href="javascript:void(0);" class="del-charge-btn" style="display:none;">
                                                                              <i class="icon-close"></i>
                                                                          </a>
                                                                    </div>
    							                				</div>
    								                         </span>
                                            </div>
                                            <div class="checkbox checkbox-info checkbox-inline prize">
                                                <input type="hidden" id="isbalance" value="{$info.is_balance}"
                                                       name="is_balance">
                                                <input type="checkbox" id="balance" class="gift-input">
                                                <label for="balance"> 奖励储值 </label>
                                                <span class="container" style="display:none;">
    							                                <div class="col-md-6 pannel charge-rule-box"
                                                                     style="float:none;margin-top:10px;margin-left: -22px;width: 400px;">
                                                                    <div style="margin-top:10px;" class="gift-record">
    											                          <input type="number" class="form-control prize-gift" min="1" onkeyup="this.value=this.value.replace(/\D/g,&#39;&#39;)" style="width: 80px;margin-left: 3px;display: inline-block;" placeholder="请填写" name="reward_balance" value="{$info.reward_balance}">
                                                                          <span style=" margin-left: 75px;line-height:38px;">元</span>
                                                                          <a href="javascript:void(0);" class="del-charge-btn" style="display:none;">
                                                                              <i class="icon-close"></i>
                                                                          </a>
                                                                    </div>
    							                				</div>
    								                         </span>
                                            </div>
                                            <div class="checkbox checkbox-info checkbox-inline prize">
                                                <input type="hidden" id="iscards" value="{$info.is_cards}"
                                                       name="is_cards">
                                                <input type="checkbox" id="cards" class="gift-input">
                                                <label for="cards"> 赠送优惠券 </label>
                                                <span class="container " style="display:none;" coupontype="0">
                                                     <a href="javascript:;" data-counts="1" id="datacount" style="color: #2db7f5;font-size: 13px;">添加赠送</a>
                                                            <div class="col-xs-10 col-sm-10 col-md-10 form1">

                                                            </div>
                                                </span>
                                            </div>

                                        </div>

                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">奖励积分：</label>
                                <div class="col-sm-10">
                                    <input type="text" value="{$info.reward_bonus}" class="form-control"
                                           oninput="value = value.replace(/[^\d.]/g, '')" name='reward_bonus'
                                           placeholder="">
                                    <div class="error">达到该等级后,会员会增加对应数额的积分</div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">奖励储值：</label>
                                <div class="col-sm-10">
                                    <input type="text" value="{$info.reward_balance}" class="form-control"
                                           oninput="value = value.replace(/[^\d.]/g, '')" name='reward_balance'
                                           placeholder="">
                                    <div class="error">达到该等级后,会员会增加对应数额的储值</div>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">会员权益：</label>
                                <div class="col-sm-10">
                            <textarea name="welfare" class="form-control" style="resize: none;"
                                      rows="3">{$info.welfare}</textarea>
                                    <div class="error"></div>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">等级封面：</label>
                                <div class="col-sm-9">
                                    <div class="ant-upload ant-upload-select ant-upload-select-picture-card ">

                                        <div class="ant-upload-list-item-info" style="display:none;" id="fimg">
                                            <div class="ant-upload ant-upload-select ant-upload-select-picture-card upload-v-img">
                                                <img src="{$info.bg_img_url}" alt="" class="img">
                                                <i class="icon-close anticon-delete coverImgDel glyphicon glyphicon-remove-circle"
                                                   data-ref="v-img-file" style=" left: 44%; "></i>

                                            </div>
                                        </div>
                                    </div>
                                    <div class="ng-scope" style="position: relative;">
                                        <span class="btn btn-default">上传图片</span>
                                        <input type="file" id="img" value="" onchange="uploads('img','file','fimg')"/>
                                        <input type="hidden" name="bg_img_url" id="logopic-upload" required
                                               value="{$info.bg_img_url}">

                                    </div>
                                    <p class="tipsInfo"> 请参照
                                        <a style="color: #2db7f5;display: inline-block;font-size: 14px;"
                                           href="https://mp.weixin.qq.com/cgi-bin/readtemplate?t=cardticket/card_cover_tmpl&amp;type=info&amp;lang=zh_CN"
                                           title="" target="_blank">图片规范</a> 上传 建议1000*600像素 格式为.jpg
                                    </p>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">等级开关：</label>
                                <div class="col-sm-9 col-xs-12 coupon-color">
                                    <div class="controls">
                                        <div class="switch" id="pay">
                                            <input type="checkbox" {if condition="$info.is_drop eq '1' " }checked{/if}/>
                                            <input type="hidden" name="is_drop" id="is_pay" value="{$info.is_drop}">
                                        </div>
                                        <div class="error">开启后不降等级。</div>

                                    </div>
                                </div>
                            </div>


                            <!--<div class="form-group">-->
                            <!--<label class="col-sm-2 col-sm-2 control-label">等级说明：</label>-->
                            <!--<div class="col-sm-10">-->
                            <!--<textarea name="welfare" class="form-control" rows="3" style="resize: none;"></textarea>-->
                            <!--<div class="error"></div>-->
                            <!--</div>-->
                            <!--</div>-->
                        </div>
                        <div class="panel-footer">
                            <input type="hidden" name="card_id" value="{$card['card_id']}">

                            <input type="hidden" id="cid" name="id" value="{$info['id']}">
                            <button type="button" class="btn btn-primary" id="creatcards-btn">保存</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
        {include file='public/footer'/}
    </div>
</section>
</body>

<script src="__STATIC_URL__/static/js/setyxhd.js?v=2"></script>

<script>
    $(function () {

        var is_balance = "{$info['is_balance']}";
        var $balance = $("#balance").parent().find(".container");
        var is_bonus = "{$info['is_bonus']}";
        var $bonus = $("#bonus").parent().find(".container");
        var is_cards = "{$info['is_cards']}";
        var $cards = $("#cards").parent().find(".container");
        if (is_bonus == "Y") {
            $("#bonus").prop("checked", true)
            $bonus.show();
        }
        if (is_cards == "Y") {
            $("#cards").prop("checked", true)
            $cards.show();
        }
        if (is_balance == "Y") {
            $("#balance").prop("checked", true)
            $balance.show();
        }

    });
    $("#pay").on('switch-change', function (e, data) {
        var $el = $(data.el), value = data.value;
        if (value == true) {
            $("#is_pay").val(1);
        } else {
            $("#is_pay").val(0);
        }
    });

    function uploads(file, name, id) {
        var formData = new FormData();
        formData.append('file', $('#' + file)[0].files[0]);
        formData.append('other', file);
        $.ajax({
            url: "{:url('uploads/upload')}",
            type: 'POST',
            cache: false,
            data: formData,
            processData: false,
            contentType: false,
        }).done(function (res) {
            console.log(res);
            $("." + file).attr("src", res.pic);
            $("#logopic-upload").val(res.pic);

            $("#" + id).attr("style", "display:block");

            $(".fengmian_img_dom").attr("src", res.pic);
            $(".fengmian_img_parent").removeClass("hide");

        }).fail(function (res) {
            alert("上传失败")
        });
    }

    $(".upload-v-img").click(function () {

        $("#fimg").attr("style", "display:none");
        $(".img").attr("src", "");
        $("#logopic-upload").val("");
        $(".fengmian_img_parent").addClass("hide");
    })
    $(function () {
        var val = $("#logopic-upload").val();
        console.log(22, val);
        if (val == "undefined" || val == "") {
            console.log(333, val);
        } else {
            $(".fengmian_img_parent").removeClass("hide")
            $("#fimg").attr("style", "display:block")
        }
    })
</script>
<script>
    $(function () {
        var id = $("#cid").val();
        $.ajax({
            url: "{:url('cardustest/getrankcardslist')}",
            type: "post",
            data: {id: id},
            success: function (data) {
                console.log(1, data);
                var text = data;
                var html8 = ""
                for (var i = 0; i < text.length; i++) {
                    if (text[i].title == null) {
                        html8 = ""
                    } else {
                        var html8 = '                        <div class="col-xs-12 col-sm-12 col-md-12 addcord" >\n' +
                            '                            <div class="gift-record">\n' +
                            '                                <select name="cardlist[zs_card_id][]"  class="form-control" >\n' +
                            '                                    <option value="' + text[i].card_id + '" data-title="' + text[i].title + ' "data-limit="' + text[i].get_limit + '">' + text[i].title + '  ( 最大可选卡券数量为' + text[i].get_limit + ')</option>\n' +
                            '                                     </select>\n' +
                            '                                <input type="number" class="form-control" min="1" placeholder="请填写" value="' + text[i].zs_no + '" name="cardlist[zs_no][]">\n' +
                            '                            </div>\n' +
                            '                             <a href="javascript:;" onclick="delsel(this)" style="font-size: 13px;">删除</a>\n' +
                            '                    </div>';
                    }
                    $('.form1').append(html8)
                }

            }
        })
        $.ajax({
            url: "{:url('cards/getpaycard')}",
            type: "post",
            data: {},
            success: function (data) {
                console.log(1, data);
                var text = data.data;
                //console.log(text);
                var option2 = "";
                for (var i = 0; i < text.length; i++) {
                    // console.log(text[i].card_id);

                    option2 += '<option value="' + text[i].card_id + '" data-title="' + text[i].title + ' "data-limit="' + text[i].get_limit + '">' + text[i].title + '  ( 最大可选卡券数量为' + text[i].get_limit + ' )</option>\n'

                }
                $('#sel1').find("select").append(option2);
                $("#opt").change(function () {

                    limit = parseInt($("#sel1").find("option:selected").attr("data-limit"));
                    var nu = parseInt($("#num").val());

                    $("#num").attr("max", limit);


                });

                $("#datacount").click(function () {


                    datacount = $(this).attr('data-counts');
                    get_limit = parseInt($("#sel" + datacount).find("option:selected").attr("data-limit"));
                    num = parseInt($("#sel" + datacount).find("input").val());
                    val = $("#sel" + datacount).find("option:selected").val();
                    if ($("#sel" + datacount).find("option:selected").val() == "") {
                        alert("卡券选项不能为空");
                        return;
                    }
                    else if (num > get_limit) {
                        console.log(num, get_limit);
                        console.log(num > get_limit);
                        alert("你选择的卡券数量超过了该卡券的领取数量!");
                        return;
                    }
                    else {

                        datacount2 = parseInt(datacount) + 1;
                        $(this).attr('data-counts', datacount2);
                        var html1 = '                        <div class="col-xs-12 col-sm-12 col-md-12 addcord" >\n' +
                            '                            <div class="gift-record"id="sel' + datacount2 + '">\n' +
                            '                                <select name="cardlist[zs_card_id][]"  class="form-control" >\n' +
                            '                                    <option value="" selected="selected">--请选择--</option>\n';

                        var html3 = '                                </select>\n' +
                            '                                <input type="number" class="form-control" min="1" placeholder="请填写" value="1" name="cardlist[zs_no][]">\n' +
                            '                            </div>\n' +
                            '                             <a href="javascript:;" onclick="delsel(this)" style="font-size: 13px;">删除</a>\n' +
                            '                    </div>';

                        $('.form1').append(html1 + option2 + html3);

                        $("#sel" + datacount2).find("select").change(function () {

                            limit = $("#sel" + datacount2).find("option:selected").attr("data-limit");
                            $("#sel" + datacount2).find("input").attr("max", limit);


                        });

                    }


                })
            }
        })


    })
</script>
<script>
    $("#creatcards-btn").click(function () {
        var live_title = $("#live_title").val();
        var live = $("#live").val();
        var growup = $("#growup").val();
        var discount = $("#discount").val();
        var welfare = $("#welfare").val();
        var logopic = $("#logopic-upload").val();
        var items = document.getElementsByTagName('select'),
            len = items.length,
            i = 0,
            valMap = {},
            sel,
            val;

        // 遍历并保存各个下拉列表的值于valMap
        for (; i < len; i++) {
            sel = items[i];
            val = sel.options[sel.selectedIndex].value;

            // 没有相同的取值时保存该值，否则返回false
            if (!valMap[val]) {
                valMap[val] = 1;
            } else {
                layer.msg('请删除重复的卡券！');
                return false;
            }

        }

        if (live_title == "") {
            layer.msg('请填写等级名称！');
            return false;
        }
        if (live == "") {
            layer.msg('请填写等级！');
            return false;
        }

        if (growup == "") {
            layer.msg('请填写所需成长值！');
            return false;
        }
        if (discount == "") {
            layer.msg('请填写折扣系数(%)！');
            return false;
        }
        if (welfare == "") {
            layer.msg('请填写会员权益！');
            return false;
        }


        $.ajax({
            url: "{:url('')}",
            type: "post",
            data: $("#creatcards").serialize(),
            success: function (data) {
                console.log(data);
                if (data.code == 0) {
                    layer.msg(data.message);
                    setTimeout(function () {
                        window.location.reload("{:url('cardus/ranklist',['card_id'=>$info['card_id']])}");

                    }, 1500)
                } else {
                    layer.msg(data.message);
                }
            }
        })

    })
</script>
<script>

    function delsel(obj){
//
        $(obj).parent().remove();


    }

</script>
</html>
